#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m), prea(n + 1, 0), preb(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        prea[i + 1] = prea[i] + a[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
        preb[i + 1] = preb[i] + b[i];
    }
    int ans = 0;
    for (int i = 1, j = 1; i <= n && j <= m;)
    {
        if (prea[i] == preb[j])
        {
            i++, j++;
        }
        else if (prea[i] > preb[j])
        {
            ans++;
            j++;
        }
        else
        {
            ans++;
            i++;
        }
    }
    cout << ans;

    return 0;
}